package com.trip_memories;

import java.util.List;
import java.util.UUID;

import signedUser.ChosedAlbum;
import signedUser.Signed;
import adapters.MyArrayAdapter;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import blogic.AccesBussineLogic;
import blogic.BusinessLogic;
import dbmodels.Album;

public class ViewAlbum extends ListActivity {

	UUID userId;
	Album[] albums;
	BusinessLogic bL;
	ArrayAdapter<Album> aa;
	ContentResolver con;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		userId = Signed.getId();
		bL = AccesBussineLogic.getBussinesLogic(this);
		List<Album> as = bL.getAlbums(userId);
		albums = new Album[as.size()];

		int count = 0;
		for (Album album : as)
			albums[count++] = album;

		ListView myListView = getListView();
		myListView.addHeaderView(getLayoutInflater().inflate(R.layout.header,
				null));
		MyArrayAdapter m = new MyArrayAdapter(this, albums);
		m.setNotifyOnChange(true);
		setListAdapter(m);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		try {
			aa.notifyDataSetChanged();
		} catch (Exception e) {

		}
		super.onListItemClick(l, v, position, id);
		Intent i = new Intent(ViewAlbum.this, ViewSelectedAlbum.class);
		ChosedAlbum.setId(albums[position - 1].getId());
		i.putExtra("userid", albums[position - 1].getId().toString());
		startActivity(i);

	}
}
